package com.gaoyang.task;

import com.gaoyang.domain.MinshengUser;
import com.gaoyang.thread.MinshengThread;
import com.gaoyang.util.Base64Img;
import com.gaoyang.util.Chaojiying;
import com.gaoyang.util.DateUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

@Component
public class ScheduledTasks4Minsheng {

    private Logger logger = LogManager.getLogger(MinshengTask.class);

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private MinshengTask task;

    public void saveCode() {

    }

    @Autowired
    private Task task_1;

//    @Scheduled(fixedRate = 100)
    public void testRsync() throws Exception{
        MinshengUser user_gaoyang = new MinshengUser();
        user_gaoyang.setUsername("高洋");
        user_gaoyang.setUserKey("OSwqfpUTZyO%2F43BgbctUjmxnOSnWAEQN");
        user_gaoyang.setCmbc_uuid("e128c7be06a8f6c36beed417437bead7bd1e69b41b5b445194d31e62e503a0b7");

        MinshengUser user_jiali = new MinshengUser();
        user_jiali.setUsername("佳丽");
        user_jiali.setUserKey("SDyQNT1ER92SNKk7pyocCU5vtwyO6SD%2F");
        user_jiali.setCmbc_uuid("7037c614d22c4a10dfd8ac5cf6e4e41aa2c3b01b9c29c61994d31e62e503a0b7");

        MinshengUser user_zhiqiang = new MinshengUser();
        user_zhiqiang.setUsername("志强");
        user_zhiqiang.setUserKey("LMd9ULmfKbfQMAVhE1XXExg6duSPo4Jd");
        user_zhiqiang.setCmbc_uuid("934ef7c31fea7d5a667d581b383b5f7fe62a7712faa494e294d31e62e503a0b7");


        Future<String> task1 = task.doTaskOne(user_gaoyang);
        Future<String> task2 = task.doTaskTwo(user_jiali);
        Future<String> task3 = task.doTaskThree(user_zhiqiang);

        if (!task1.get().equals("")) logger.info(task1.get());
        if (!task2.get().equals("")) logger.info(task2.get());
        if (!task3.get().equals("")) logger.info(task3.get());
//        while(true) {
//            if(task1.isDone() && task2.isDone() && task3.isDone()) {
//                // 三个任务都调用完成，退出循环等待
//                break;
//            }
//            Thread.sleep(1000);
//        }
//        System.out.println("任务全部完成，总耗时：" + (end - start) + "毫秒");

    }

//    @Scheduled(fixedRate = 100)
//    public void testRsync1() throws Exception{
//        MinshengUser user_gaoyang = new MinshengUser();
//        user_gaoyang.setUsername("高洋");
//        user_gaoyang.setUserKey("OSwqfpUTZyO%2F43BgbctUjmxnOSnWAEQN");
//        user_gaoyang.setCmbc_uuid("e128c7be06a8f6c36beed417437bead7bd1e69b41b5b445194d31e62e503a0b7");
//        Future<String> task1 = task.doTaskOne(user_gaoyang);
//        if (!task1.get().equals("")) logger.info(task1.get());
//    }
//
//    @Scheduled(fixedRate = 100)
//    public void testRsync2() throws Exception{
//        MinshengUser user_jiali = new MinshengUser();
//        user_jiali.setUsername("佳丽");
//        user_jiali.setUserKey("SDyQNT1ER92SNKk7pyocCU5vtwyO6SD%2F");
//        user_jiali.setCmbc_uuid("7037c614d22c4a10dfd8ac5cf6e4e41aa2c3b01b9c29c61994d31e62e503a0b7");
//        Future<String> task2 = task.doTaskTwo(user_jiali);
//        if (!task2.get().equals("")) logger.info(task2.get());
//    }
//
//    @Scheduled(fixedRate = 100)
//    public void testRsync3() throws Exception{
//        MinshengUser user_zhiqiang = new MinshengUser();
//        user_zhiqiang.setUsername("志强");
//        user_zhiqiang.setUserKey("LMd9ULmfKbfQMAVhE1XXExg6duSPo4Jd");
//        user_zhiqiang.setCmbc_uuid("934ef7c31fea7d5a667d581b383b5f7fe62a7712faa494e294d31e62e503a0b7");
//        Future<String> task3 = task.doTaskThree(user_zhiqiang);
//        if (!task3.get().equals("")) logger.info(task3.get());
//    }

}